iT邦幫忙

2023 iThome 鐵人賽

DAY 28
0
Modern Web

tailwindcss - 從零開始學系列 第 28

tailwindcss - 從零開始學 - Day28 - 使用插件

  • 分享至 

  • xImage
  •  

雖然在 tailwindcss 可以製作出豐富的 UI 元件,但還是有許多已經寫好的元件可以直接使用,不需要重複製作輪子。

這個單元將討論 tailwindcss 插件的安裝與使用方式,這裡介紹一個文章閱讀的版面插件。

要製作這個文章閱讀版面需要安裝外掛套件,先安裝套件 typography:

npm install -D @tailwindcss/typography

在 tailwind.config.js 檔案新增 plugin:

module.exports = {
  theme: {
    // ...
  },
  plugins: [
    require('@tailwindcss/typography'),
    // ...
  ],
}

接下來就可以直接在 html 套用這個插件的樣式,一個最簡單的文章閱讀版型:

<article class="prose lg:prose-xl">
  <h1>Garlic bread with cheese: What the science tells us</h1>
  <p>
    For years parents have espoused the health benefits of eating garlic bread with cheese to their
    children, with the food earning such an iconic status in our culture that kids will often dress
    up as warm, cheesy loaf for Halloween.
  </p>
  <p>
    But a recent study shows that the celebrated appetizer may be linked to a series of rabies cases
    springing up around the country.
  </p>
  <!-- ... -->
</article>

就會呈現這個樣子:

https://ithelp.ithome.com.tw/upload/images/20231005/201626070KVF2CBYV1.png

接下來根據這個模板,改良成為最好看的版型:

<div class="mx-auto max-w-4xl px-4 py-16 text-xl tracking-wide sm:py-24 sm:px-6 md:px-12">
  <article class="prose lg:prose-xl">
    <h1>Garlic bread with cheese: What the science tells us</h1>
    <p>For years parents have espoused the health benefits of eating garlic bread with cheese to their children, with the food earning such an iconic status in our culture that kids will often dress up as warm, cheesy loaf for Halloween.</p>
    <p>But a recent study shows that the celebrated appetizer may be linked to a series of rabies cases springing up around the country.</p>
    <!-- ... -->
  </article>
</div>

就會呈現這個樣子:

https://ithelp.ithome.com.tw/upload/images/20231005/20162607NlfvAW8h0h.png

今日完整範例

tailwindcss - 從零開始學 - Day28 [完]


上一篇
tailwindcss - 從零開始學 - Day27 - 設定檔
下一篇
tailwindcss - 從零開始學 - Day29 - 下拉式選單插件
系列文
tailwindcss - 從零開始學30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言